#include "gtest/gtest.h"

#include "Graph.h"

class GraphTest : public ::testing::Test {
	protected:
		virtual void SetUp() {
		}
		virtual void TearDown() {
		}

	public:
};

TEST_F(GraphTest, NumVertices_OK) {
	Graph g(2, false);
	ASSERT_EQ(2, g.numVertices());
}

TEST_F(GraphTest, Directed_OK) {
	Graph g(2, true);
	ASSERT_EQ(true, g.directed());
}

TEST_F(GraphTest, Undirected_OK) {
	Graph g(2, false);
	ASSERT_EQ(false, g.directed());
}

TEST_F(GraphTest, IsEdge_NoEdgeExist) {
	Graph g(2, false);
	ASSERT_EQ(false, g.isEdge(0, 1));
}

TEST_F(GraphTest, IsEdge_OneEdgeExist) {
	Graph g(2, false);
	g.addEdge(0, 1);
	ASSERT_EQ(true, g.isEdge(0, 1));
}

TEST_F(GraphTest, AddEdge_Directed) {
	Graph g(2, true);
	g.addEdge(0, 1);
	ASSERT_EQ(true, g.isEdge(0, 1));
	ASSERT_EQ(false, g.isEdge(1, 0));
}

TEST_F(GraphTest, AddEdge_UnDirected) {
	Graph g(2, false);
	g.addEdge(0, 1);
	ASSERT_EQ(true, g.isEdge(0, 1));
	ASSERT_EQ(true, g.isEdge(1, 0));
}

TEST_F(GraphTest, AddEdge_DirectWithWeight) {
	Graph g(2, true);
	g.addEdge(0, 1, 100);
	ASSERT_EQ(100, g.edgeWeight(0, 1));
}

TEST_F(GraphTest, AddEdge_UnDirectWithWeight) {
	Graph g(2, false);
	g.addEdge(0, 1, 100);
	ASSERT_EQ(100, g.edgeWeight(1, 0));
}

TEST_F(GraphTest, AddEdge_DupulicationIsNotAdded) {
	Graph g(2, false);
	g.addEdge(0, 1);
	g.addEdge(0, 1);

	int edgeCount = 0;
	for(VertexList::const_iterator it = g.begin(0); it != g.end(0); ++it)
	{
		++edgeCount;
	}
	ASSERT_EQ(1, edgeCount);
}

TEST_F(GraphTest, RemoveEdge_Direct) {
	Graph g(2, true);
	g.addEdge(0, 1);
	g.removeEdge(0, 1);
	ASSERT_EQ(false, g.isEdge(0, 1));
}

TEST_F(GraphTest, RemoveEdge_UnDirect) {
	Graph g(2, false);
	g.addEdge(0, 1);
	g.removeEdge(0, 1);
	ASSERT_EQ(false, g.isEdge(0, 1));
}

TEST_F(GraphTest, Iterator_1stList) {
	Graph g(3, false);
	g.addEdge(0, 1, 100);
	g.addEdge(1, 2, 200);

	int weight = 0;
	for(VertexList::const_iterator it = g.begin(0); it != g.end(0); ++it)
	{
		weight =  g.edgeWeight(0, 1);
	}

	ASSERT_EQ(100, weight);
}

TEST_F(GraphTest, Iterator_2ndList) {
	Graph g(3, false);
	g.addEdge(0, 1, 100);
	g.addEdge(1, 2, 200);

	int weight = 0;
	for(VertexList::const_iterator it = g.begin(1); it != g.end(1); ++it)
	{
		weight =  g.edgeWeight(1, 2);
	}

	ASSERT_EQ(200, weight);
}

